/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-05-04 09:50:21
 * @LastEditTime : 2023-08-22 15:12:15
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Common\Router\MenuNav\FirstLevel\AiPicture.jsx
 * @Description  :
 */
import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { DelDataButton, AnnexButton, CommonButton, OpenSelection } from '../Common/options'

const independenceList = {
    'jtgjadmin.ljkjkf.com': 'organizationUuid',
    'jtgjadmin.hljsjtgj.com': 'organizationUuid',
}

export const AiPicture = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    const { hostname } = window.location
    let data = {
        pageSize: 10,
        params: { pageIndex: 1, OrderField: 'logTime@desc' },
        get: API_LIST()[`get${url}`],
        independenceSet: {
            title: '组织机构',
            url: 'getOrgTree',
            data: { IsByUserUuid: 1 },
            type: 'TableNavTree001',
            all: true,
        },
        options: e => {
            return [
                <OpenSelection
                    OptionsEvent={OptionsEvent}
                    title="批量删除"
                    type="primary"
                    danger
                    data={{
                        type: 'SelectionDelete',
                        url: 'posBatchRemoveAiPictures',
                    }}
                />,
            ]
        },

        independence: independenceList[hostname],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        columns: [
            commonTableList.uuid,
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },
            {
                dataIndex: 'algorithmName',
                title: '预警类型',
                valueType: 'Date',

                rules: true,
                width: 150,
            },
            {
                dataIndex: 'logTime',
                title: '预警时间',
                valueType: 'Date',
                showTime: true,

                rules: true,
                width: 150,
            },
            {
                dataIndex: 'handleTime',
                title: '处理时间',
                valueType: 'Date',
                showTime: true,

                rules: true,
                width: 150,
            },
            {
                dataIndex: 'handleUserName',
                title: '处理人员',
                valueType: 'input',

                rules: true,
                width: 200,
            },
            {
                dataIndex: 'handled',
                title: '是否处理',
                valueType: 'select',
                valueEnum: { 0: '否', 1: '是' },

                rules: true,
                width: 150,
            },

            { ...commonTableList.StartTime, title: '预警开始' },
            { ...commonTableList.EndTime, title: '预警结束' },
            { ...commonTableList.BeginProduce, title: '处理开始' },
            { ...commonTableList.EndProduce, title: '处理结束' },

            commonTableList.remark,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 240,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, originalPictureUrl, resultPictureUrl, handleTime, aiPictureAttachment } = record
                    return [
                        !handleTime && (
                            <CommonButton
                                key="submit"
                                OptionsEvent={OptionsEvent}
                                title="预警处理"
                                data={{
                                    type: 'AIPicturesModal',
                                    record,
                                    width: 1000,
                                    actionRef,
                                    url: 'putAiPicture',
                                    uuid,
                                }}
                            />
                        ),
                        <AnnexButton OptionsEvent={OptionsEvent} key="one" url={originalPictureUrl} title="原图" />,
                        <AnnexButton OptionsEvent={OptionsEvent} key="two" url={resultPictureUrl} title="预警图" />,
                        handleTime && (
                            <AnnexButton
                                OptionsEvent={OptionsEvent}
                                key="thr"
                                url={aiPictureAttachment?.attachment?.fileUrl}
                                title="处理结果"
                            />
                        ),
                        <DelDataButton
                            OptionsEvent={OptionsEvent}
                            key="del"
                            title="删除"
                            url={url}
                            uuid={record.uuid}
                        />,
                    ]
                },
            },
        ],
    }

    return data
}
